package com.bhs.sansonglogistics.ui.adapter;

import android.text.TextUtils;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bhs.sansonglogistics.R;
import com.bhs.sansonglogistics.bean.FeeDetail;
import com.bhs.sansonglogistics.bean.PictureShowBean;
import com.bhs.sansonglogistics.utils.MyUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.util.SmartGlideImageLoader;

import java.util.ArrayList;
import java.util.List;

/**
 * 未支付列表
 */
public class UnpaidAdapter extends BaseQuickAdapter<FeeDetail, BaseViewHolder> {


    private int type;

    public UnpaidAdapter(@Nullable List<FeeDetail> data, int type) {
        super(R.layout.item_unpaid, data);
        this.type = type;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, FeeDetail item) {
        //未支付的费用类型
        helper.setText(R.id.tv_cost_type, item.getFee_notice());
        if (item.getFee_notice().equals("运费")) {
            helper.setText(R.id.tv_type, type == 1 ? "发货人支付" : "收货人支付");
        } else {
            helper.setText(R.id.tv_type, "运输凭证");
        }
        //未支付的钱
        helper.setText(R.id.tv_porterage, String.format("%s元", item.getMoney()));
        //待支付
        RecyclerView rvTransportDocument = helper.getView(R.id.rv_transport_document);
        PictureShowAdapter pictureShowAdapter2 = new PictureShowAdapter(R.layout.item_picture3);
        rvTransportDocument.setAdapter(pictureShowAdapter2);

        if (!TextUtils.isEmpty(item.getFee_pic())) {
            String[] feePic = item.getFee_pic().split("\\|\\|");
            List<PictureShowBean> pictureShowBeanList = new ArrayList<>();
            List<Object> urls2 = new ArrayList<>();
            for (String s : feePic) {
                pictureShowBeanList.add(new PictureShowBean(s));
                urls2.add(MyUtils.watermark(s));
            }
            pictureShowAdapter2.setNewData(pictureShowBeanList);
            pictureShowAdapter2.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                    new XPopup.Builder(mContext)
                            .asImageViewer(view.findViewById(R.id.iv_picture), position, urls2, null, new SmartGlideImageLoader())
                            .isShowSaveButton(false)
                            .show();
                }
            });
        }

        rvTransportDocument.setLayoutManager(new GridLayoutManager(mContext, 3));
    }
}
